package com.abigdreamer.im.server.serverConfig;

import com.abigdreamer.im.server.tools.ServerUtils;

public class ServerConfigFactory {

	/**
	 * 
	 * @param <T>
	 * @param c
	 * @return
	 */
	public static <T extends Config> T createConfig(Class<T> c){
		Config config=null;
		try {
			 //产生一个人种
			config = (Config)Class.forName(c.getName()).newInstance(); 
			EIMServerConfig serverConfig=ServerUtils.getServerConfig();
			if(config.getClass().equals(EIMChatSocketConfig.class)){
				config=serverConfig.getChatSocketConfig();
			}else if(config.getClass().equals(EIMFileSocketConfig.class)){
				config=serverConfig.getFileSocketConfig();
			}else if(config.getClass().equals(EIMDBServerConfig.class)){
				config=serverConfig.getDBInfo();
			}else if(config.getClass().equals(EIMServerConfig.class)){
				config=serverConfig;
			}else{
				System.out.println("生成错误！");
			}
		} catch (Exception e) {
			System.out.println("类型生成错误！");
		}
		return (T)config;
	}
}
